# fun_log.py
import datetime

def write(log_data, log_file="application.log"):
    """
    写日志到指定文件

    Args:
        log_data (bytes): 需要记录的日志数据
        log_file (str): 日志文件名，默认为 application.log
    """
    try:
        with open(log_file, "a", encoding="utf-8") as file:
            timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            file.write(f"[{timestamp}] {log_data}\n")
            print(f"日志写入成功: {log_file}")
    except Exception as e:
        print(f"写入日志时发生错误: {e}")
